home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programmer Power Tools
/
Programmer Power Tools.iso
/
microcrn
/
issue_49.arc
/
DRV_INFO.ARC
/
DRV_INFO.PAS
Wrap
Pascal/Delphi Source File
|
1989-07-11
|
8KB
|
169 lines
(* Micro Cornucopia Magazine - Issue #49
Tech Tips Figure 1 - Find Number of Drives in System *)
(* PROGRAM DRV_INFO.PAS AUTHOR - JEFFREY SCOTT DONOVAN *)
(*------------------------------------------------------------------*)
program drv_info;
uses crt,dos; (* TURBO CRT AND DOS UNITS *)
type
drive_ids=record (* DISK-SUBSYSTEM INFORMATION *)
no_drive:integer; (* NUMBER OF TOTAL DRIVES *)
no_logical:integer; (* NUMBER OF LOGICAL DRIVES *)
no_floppy:integer; (* NUMBER OF FLOPPY DRIVES *)
no_hard:integer; (* NUMBER OF HARD DRIVES *)
drive_chars:array[1..10] of char; (* DRIVE CHARACTERS ARRAY *)
drive_type:array[1..10] of integer; (* ARRAY OF DRIVE TYPES *)
drive_numb:array[1..10] of integer; (* DOS DRIVE NUMBER ARRAY *)
c_drive:integer; (* CURRENT DRIVE *)
c_drive_ch:char; (* CURRENT DRIVE CHARACTER *)
last_drive:char; (* LAST DRIVE CHARACTER *)
end;
var
drives:drive_ids; (* GLOBAL INFO ABOUT DRIVES *)
regs:registers; (* DOS REGISTERS *)
(* MODULE : GET CURRENT DRIVE *)
(*------------------------------------------------------------------*)
(* Returns current drive number. A=1, B=2, C=3, ETC. *)
(* *)
function get_current_drive:integer;
begin
regs.ah:=$19; (* FUNCTION 19H, GET CURRENT DRV *)
intr($21,regs); (* INT 21H *)
get_current_drive:=regs.al; (* RETURN DRIVE NUMBER *)
end;
(*------------------------------------------------------------------*)
(* MODULE : GET NUMBER LOGICAL DRIVES *)
(*------------------------------------------------------------------*)
(* Return number of logical drives in system. *)
(* NOTE : DOS 3.O + returns either 5 or the last drive in system. *)
(* *)
function get_number_logical_drives:integer;
var
current:integer;
begin
current:=get_current_drive; (* GET CURRENT DRIVE TO SET TO *)
regs.ah:=$0E; (* FUNCTION 0EH, SET DRIVE *)
regs.dl:=current; (* SET TO CURRENT DRIVE *)
intr($21,regs); (* INT 21H *)
get_number_logical_drives:=regs.al; (* RETURN # LOGICAL DRIVES *)
end;
(*------------------------------------------------------------------*)
(* MODULE : GET NUMBER FLOPPY DRIVES *)
(*------------------------------------------------------------------*)
(* Return the number of floppy drives. *)
(* *)
function get_number_floppy_drives:integer;
var
drives_there,number:integer;
begin
number:=-1; (* SET NUMBER TO -1 *)
intr($11,regs); (* INT 11, EQUIPMENT INFO *)
drives_there:=regs.ax and 1; (* FLOPPY INSTALLED, BIT0 = 1 *)
if drives_there=1 then (* IF FLOPPYS INSTLLD, HOW MANY? *)
number:=(regs.ax shr 6) and 4; (* BIT 6-7 HOLD APPROP INFO *)
get_number_floppy_drives:=number+1; (* RETURN # OF FLOPPIES *)
end;
(*------------------------------------------------------------------*)
(* MODULE : GET DRIVE DATA *)
(*------------------------------------------------------------------*)
(* Get all the drive data ness. Store in global var drives. *)
(* *)
procedure get_drive_data;
var
loop,count,h_count,start:integer;
begin
count:=0; (* SET TOTAL COUNTS TO ZERO *)
h_count:=0;
for loop:=1 to drives.no_floppy do (* ASSIGN FLOPPY INFO IF ANY *)
begin (* SET CORRECT DRIVE CHARACTER *)
drives.drive_chars[loop]:=chr(loop+64);
drives.drive_type[loop]:=1; (* SET DRIVE TYPE TO FLOPPY *)
drives.drive_numb[loop]:=loop-1; (* LOGICAL DRIVE NUMBER *)
inc(count); (* INC TOTAL DRIVE COUNT *)
end;
(* NO MORE THAN 10 DRIVES *)
if (drives.no_logical>10) then drives.no_logical:=10;
start:=drives.no_floppy+1; (* FIGURE START NUMBER H-DRIVE *)
if (drives.no_floppy<=1) then inc(start);
if (drives.no_floppy=0) then inc(start);
for loop:=start to drives.no_logical do (* CHECK EACH HDRIVE *)
begin
regs.ah:=$1C; (* FUNCTION 1CH *)
regs.dl:=loop; (* SET DRIVE NUMBER TO LOOP *)
intr($21,regs); (* INT 21H *)
if (regs.al<>$FF) then (* IF DRIVE IS VALID, SET APPR. *)
begin (* SET CORRECT DRIVE CHARACTER *)
(* SET DRIVE TYPE TO H-DRIVE *)
(* FIGURE ACTUAL LOGICAL DRIVE # *)
drives.drive_chars[loop-start+drives.no_floppy+1]:=
chr(loop+64);
drives.drive_type[loop-start+drives.no_floppy+1]:=2;
drives.drive_numb[loop-start+drives.no_floppy+1]:=loop-1;
inc(count); (* INC TOTAL DRIVE COUNT *)
inc(h_count); (* INC H-DRIVE COUNT *)
end;
end;
drives.no_hard:=h_count; (* ASSIGN NUMBER HARD DRIVES *)
(* ASSIGN NUMBER OF TOTAL DRIVES *)
drives.no_drive:=h_count+drives.no_floppy;
end;
(*------------------------------------------------------------------*)
(* MODULE : WRITE DISK CHOICES *)
(*------------------------------------------------------------------*)
(* Write all available drives (up to 10), and write the drive type. *)
(* *)
procedure write_disk_choices;
var loop:integer;
begin
for loop:=1 to drives.no_drive do (* LOOP FROM FIRST TO LAST *)
begin
write(drives.drive_chars[loop],': ');(* WRITE DRIVE CHARACTER *)
(* WRITE DRIVE TYPE *)
if (drives.drive_type[loop]=1) then write('[ Floppy ]')
else write('[ H-Drive ]');
(* WRITE LOGICAL DRIVE NUMBER *)
writeln(' ,DOS Logical Disk # ',drives.drive_numb[loop]:2);
end;
end;
(*------------------------------------------------------------------*)
begin
clrscr;
(* GET ALL THE DRIVE INFO *)
drives.no_floppy:=get_number_floppy_drives;
drives.no_logical:=get_number_logical_drives;
drives.c_drive:=get_current_drive;
get_drive_data;
drives.c_drive_ch:=chr(drives.c_drive+65);
drives.last_drive:=chr(drives.no_logical-drives.no_floppy+65);
(* WRITE ALL THE DISK INFO *)
writeln('SYSTEM DISK INFORMATION');
writeln('-----------------------');
writeln('Number Logical Drives = ',drives.no_logical:1);
writeln('Number Floppy Drives = ',drives.no_floppy:1);
writeln('Number Hard Drives = ',drives.no_hard:1);
writeln('Current Drive = ',drives.c_drive_ch);
writeln('Last Drive = ',drives.last_drive);
writeln;
writeln('ACTUAL DRIVES IN SYSTEM');
writeln('-----------------------');
write_disk_choices;
end.